use crossterm::event::{read, Event::Key, KeyEvent};

use xxx_editor::{EditorResult, ResultCode};

#[derive(Debug)]
pub struct Keyboard;

impl Keyboard {
  pub fn read(&mut self) -> EditorResult<KeyEvent, ResultCode> {
    loop {
      if let Ok(event) = read() {
        if let Key(key_event) = event {
          return Ok(key_event);
        }
      } else {
        return Err(ResultCode::KeyReadFail);
      }
    }
  }
}
